(function() {
	var page = $(".activiti-form", DWZ.context());
	//条件下拉区域隐藏
	function removeDropdown() {
		$("div.dropdown-down", page).each(function() {
			$(this).removeClass('dropdown-down');
			$(this).parent().removeClass('li-hover');
			$(this).removeClass('dropdown-info-bar-down');
			if ($(this).find("div.text-area").length != 0) {
				textAreaChange(this);
			} else if ($(this).find("div.js-picker-ui").length != 0) {
				dateAreaChange(this);
			} else if ($(this).find("div.number-area").length != 0) {
				numberAreaChange(this);
			} else if ($(this).find("div.enum-area").length != 0) {
				enumAreaChange(this);
			} else if ($(this).find("div.check-list-field-container").length != 0) {
				userAreaChange(this);
			}
		});
	}
	//清除时间条件文本域
	function clearInput(thiz) {
		$this = $(thiz);
		$li.attr("fieldValue", "");
		$li.attr("fieldValues", "");
		$li.attr("startValue", "");
		$li.attr("endValue", "");
		$li.attr("timeUnit", "");
	}
	//用户查询条件提交
	function userAreaChange(thiz) {
		$this = $(thiz);
		$li = $this.parent();
		var $input = $this.find("div.check-list-field-container").find("input[data-type=user]");
		$input.val('');
		$input.trigger("input");
		var text = '';
		var fieldValues = '';
		if ($this.find("ul.checked-list-section>li").length != 0) {
			var lables = $this.find("ul.checked-list-section>li>label");
			$.each(lables, function(n, lable) {
				text = text + $(lable).text() + ",";
				fieldValues = fieldValues + $(lable).attr("val") + ",";
			});
			text = text.substring(0, text.length - 1);
			fieldValues = fieldValues.substring(0, fieldValues.length - 1);
		} else {
			text = "所有";
		}
		$li.attr("operator", "IN");
		$li.attr("fieldValues", fieldValues);
		if (text.length > 15) {
			text = text.substring(0, 15) + "…";
		}
		$this.parent().find("span.drop-text").html(text);
	}
	//文本类型查询条件提交
	function textAreaChange(thiz) {
		$this = $(thiz);
		$li = $this.parent();
		var text1 = $this.find("div.text-area>input:eq(0)").val();
		var text2 = $this.find("div.text-area>input:eq(1)").val();
		var selectValue = $this.find("div.text-area>select").children('option:selected').val();
		var text;
		clearInput($li);
		if (selectValue == "CT") {
			$li.attr("operator", "CT");
			$li.attr("fieldValue", text1);
			if (text1 != "") {
				text = "包含 " + text1;
			} else {
				text = "所有";
			}
		} else if (selectValue == "EQ") {
			$li.attr("operator", "EQ");
			$li.attr("fieldValue", text1);
			if (text1 != "") {
				text = "等于 " + text1;
			} else {
				text = "所有";
			}
		} else if (selectValue == "BT") {
			$li.attr("operator", "BT");
			$li.attr("startValue", text1);
			$li.attr("endValue", text2);
			if (text1 != "" && text2 != "") {
				text = "介于" + text1 + "和" + text2 + "之间";
			} else if (text1 != "" && text2 == "") {
				text = "大于" + text1;
			} else if (text1 == "" && text2 != "") {
				text = "小于" + text2;
			} else {
				text = "所有";
			}
		}
		if (text.length > 15) {
			text = text.substring(0, 15) + "…";
		}
		$li.find("span.drop-text").html(text);
	}
    //数字类型条件提交
	function numberAreaChange(thiz) {
		$this = $(thiz);
		$li = $this.parent();
		var text1 = $this.find("div.number-area>input:eq(0)").val();
		var text2 = $this.find("div.number-area>input:eq(1)").val();
		var selectValue = $this.find("div.number-area>select").children('option:selected').val();
		var text;
		clearInput($li);
		if (selectValue == "EQ") {
			$li.attr("operator", "EQ");
			$li.attr("fieldValue", text1);
			if (text1 != "") {
				text = "等于 " + text1;
			} else {
				text = "所有";
			}
		} else if (selectValue == "BT") {
			$li.attr("operator", "BT");
			$li.attr("startValue", text1);
			$li.attr("endValue", text2);
			if (text1 != "" && text2 != "") {
				text = "介于" + text1 + "和" + text2 + "之间";
			} else if (text1 != "" && text2 == "") {
				text = "大于" + text1;
			} else if (text1 == "" && text2 != "") {
				text = "小于" + text2;
			} else {
				text = "所有";
			}
		}
		if (text.length > 15) {
			text = text.substring(0, 15) + "…";
		}
		$this.find("span.drop-text").html(text);
	}
    //日期条件提交
	function dateAreaChange(thiz) {
		$li = $(thiz).parent();
		var $div = $(thiz).find("div.js-picker-ui input[type='radio']:checked").parent();
		clearInput($li);
		if ($div.hasClass('withinTheLast')) {
			var num = $div.find('input.js-val').val();
			var selectValue = $div.find("select").children('option:selected').val();
			$li.attr("operator", "SC");
			if (num != '') {
				$li.attr("fieldValue", num);
				$li.attr("timeUnit", selectValue);
				var type;
				if (selectValue == "MINUTE") {
					type = "分";
				} else if (selectValue == "HOUR") {
					type = "小时";
				} else if (selectValue == "DAY") {
					type = "天";
				}
				text = "在过去" + num + type + "内";
			} else {
				text = "所有";
			}
		} else {
			var text1 = $div.find('input.date:eq(0)').val();
			var text2 = $div.find('input.date:eq(1)').val();
			$li.attr("operator", "BT");
			$li.attr("startValue", text1);
			$li.attr("endValue", text2);
			if (text1 != "" && text2 != "") {
				text = "在" + text1 + "和" + text2 + "之间";
			} else if (text1 != "" && text2 == "") {
				text = "大于" + text1;
			} else if (text1 == "" && text2 != "") {
				text = "小于" + text2;
			} else {
				text = "所有";
			}
		}
		if (text.length > 15) {
			text = text.substring(0, 15) + "…";
		}
		$(thiz).find("div.js-picker-ui").parent().parent().find("span.drop-text").html(text);
	}
	//枚举条件提交
	function enumAreaChange(thiz) {
		$this = $(thiz);
		$li = $this.parent();
		var selectText = $this.find("div.enum-area>select").children('option:selected').text();
		var selectValue = $this.find("div.enum-area>select").children('option:selected').val();
		var text;
		clearInput($li);
		$li.attr("operator", "EQ");
		$li.attr("fieldValue", selectValue);
		if (selectText != "") {
			text = selectText;
		} else {
			text = "所有";
		}
		if (text.length > 15) {
			text = text.substring(0, 15) + "…";
		}
		$li.find("span.drop-text").html(text);
	}

	//提交全部查询条件
	function submitQuery() {
		$("div.dropdown", page).each(function() {
			if ($(this).find("div.text-area").length != 0) {
				textAreaChange(this);
			} else if ($(this).find("div.js-picker-ui").length != 0) {
				dateAreaChange(this);
			} else if ($(this).find("div.number-area").length != 0) {
				numberAreaChange(this);
			} else if ($(this).find("div.enum-area").length != 0) {
				enumAreaChange(this);
			} else if ($(this).find("div.check-list-field-container").length != 0) {
				userAreaChange(this);
			}
		});
	}
	
	//调整分页条位置
	function resizePageBar() {
		var barHeight = parseInt($('div.search-criteria-container', page).height());
		var n = barHeight - 65;
		$('#table div.gridScroller,page').attr("layoutH", 176 + n);
		$(window).resize();
	}
	$(function() {
		//页面渲染完成之后执行
		page.on('uiComplete', function() {
			//隐藏不需要的列
			$("#head th", page).each(function() {
				if (typeof($(this).attr("visible")) == "undefined") {
					$(this).addClass('hidden');
					$('#tbody').find("td[field=" + $(this).attr('field') + "]").addClass('hidden');
				}
			});
			//提交查询
			submitQuery();
			//重置分页条位置
			setTimeout(function() {
				resizePageBar()
			}, 5);
		});
		
		//数字类型文本框输入限制
		page.on('keyup', "input[data-type='number']", function() {
			var tmptxt = $(this).val();
			$(this).val(tmptxt.replace(/\D/g, ''));
		}).bind("paste", function() {
			var tmptxt = $(this).val();
			$(this).val(tmptxt.replace(/\D/g, ''));
		}).css("ime-mode", "disabled");

		//点击某一查询条件
		$("ul.criteria-list", page).on('click', 'li.condition', function(e) {
			if ($(e.target).parents(".check-list-field-container").length == 0) {
				var $li = $(this);
				if (!$li.hasClass('li-hover')) {
					//隐藏其他下拉条件
					removeDropdown();
					//展示该条件下拉区域
					$li.addClass("li-hover");
					$li.find("div.dropdown").addClass("dropdown-down");
					$li.find("div.dropdown-info-bar").addClass("dropdown-info-bar-down");
				}
			}
		});
		//点击查询条件以外的浏览器任意位置，关闭下拉区域
		$(document).click(function(e) {
			if ($("div.dropdown-down").length > 0) {
				if ($(e.target).parents(".criteria-list > li").length == 0 && $(e.target).parents("#calendar>.main").length == 0
				&& !$(e.target).hasClass("current-user-remove")) {
					removeDropdown();
				}
			}
		});
		
		//文本条件表达式更改
		page.on('change', '.js-text-expression', function() {
			if ($(this).children('option:selected').val() == "BT") {
				$(this).parent().find("input:eq(1)").show();
			} else {
				$(this).parent().find("input:eq(1)").hide();
				$(this).parent().find("input:eq(1)").val("");
			}
		});
		
		//数字条件表达式更改
		page.on('change', '.js-number-expression', function() {
			if ($(this).children('option:selected').val() == "BT") {
				$(this).parent().find("input:eq(1)").show();
			} else {
				$(this).parent().find("input:eq(1)").val("");
				$(this).parent().find("input:eq(1)").hide();
			}
		});

		//用户搜索文本框变事件
		page.on('input propertychange', '.check-list-field', function() {
			if ($(this).val()) {
				//展示清除按钮
				var $span = $(this).parent().find(".aui-iconfont-search");
				$span.removeClass('aui-iconfont-search');
				$span.addClass('clear-field aui-iconfont-remove');
				$span.click(function(e) {
					var $input = $(this).parent().find(".check-list-field");
					$input.val('');
					$input.trigger("input");
				});
				var $div = $(this).parent();
				var $ul = $div.find('ul.suggest-list-section');
				$ul.find("li").remove();
				var $checkedUl = $div.find('ul.checked-list-section');
				DWZ.ajax({
					type: 'POST',
					url: 'user/userSuggest',
					data: {
						userCode: $(this).val()
					},
					dataType: "json",
					cache: false,
					success: function(data) {
						$.each(data, function(n, value) {
							var check = "";
							if ($checkedUl.find("li[user=" + value.userCode + "]").length != 0) {
								check = "checked";
							}
							$ul.append("<li class='check-list-item'><label class='item-label' title='" + value.userText + "' data-descriptor-title='"
							+ value.userText + "'><input class='user-check' type='checkbox' " + check + " value='" + value.userCode + "' text="
							+ value.userText + ">" + value.userCode + "(" + value.userText + ")" + "</label></li>");
						});
					}
				});

			} else {
				var $span = $(this).parent().find(".aui-iconfont-remove");
				$span.removeClass('clear-field aui-iconfont-remove');
				$span.addClass('aui-iconfont-search');
				$span.unbind("click");
				var $ul = $(this).parent().find('ul.suggest-list-section');
				$ul.find("li").remove();
			}
		});

		//用户勾选事件
		page.on('click', 'input[type=checkbox].user-check', function() {
			var $container = $(this).parent().parent().parent().parent();
			if (this.checked) {
				$container.find('.checked-list-section').append("<li class='check-list-item' user=" + $(this).val()
				+ "><label class='item-label current-user' val='" + $(this).val() + "' title=" + $(this).attr("text") + ">"
				+ $(this).parent().attr('title') + "</label><span class='current-user-remove aui-icon aui-icon-small'></span></li>")
			} else {
				$container.find('.checked-list-section').find("li[user=" + $(this).val() + "]").remove();
			}
		});

		//移除当前用户
		page.on('click', 'span.current-user-remove', function() {
			var value = $(this).parent().find('label').attr('val');
			var $check = $(this).parents('.check-list-field-container:first').find("input[value=" + value + "]");
			if ($check.length != 0) {
				$check.removeAttr('checked');
			}
			$(this).parent().remove();
		});
		
		//列调整保存事件
		$('#column-ok', page).click(function() {
			var colums = $('#drop-column li input:checked', page);
			if (colums.length > 0) {
				$('#head', page).find('th').addClass('hidden');
				$('#tbody', page).find('td').addClass('hidden');
				$.each(colums, function(n, input) {
					$('#head', page).find("th[field=" + $(input).val() + "]").removeClass('hidden');
					$('#tbody', page).find("td[field=" + $(input).val() + "]").removeClass('hidden');
				});
				$.jTableTool.initGridColumnWidth($("#table"));
			} else {
				alertMsg.warn('请至少选择一列！');
				var cls = $('#head').find('th:not(.hidden)');
				$.each(cls, function(n, colum) {
					$("#drop-column li input[value=" + $(colum).attr("field") + "]", page).attr("checked", "checked");
				});
			}
		});
		
		//添加查询条件
		$("#all-condition", page).on('click', 'input[type=checkbox]', function() {
			var type = $(this).attr('control-type');
			var text = $(this).parent().text();
			var field = $(this).val();
			var businessField = $(this).attr('businessField');
			if ((type == "STRING" || type == "TEXT") && field != "CREATEUSER" && field != "MODIFYUSER") {
				$('.search-criteria-extended>ul').append("<li class='condition queryCondition' field='"
				+ field
				+ "' businessField='"
				+ businessField
				+ "' text="
				+ text
				+ " type="
				+ type
				+ "><a href='#' class='drop'>"
				+ text
				+ "：<span class='drop-text'>所有</span></a>"
				+ " <a href='#' class='remove-filter' title='删除条件' style='display: inline;'><span class='condition-remove aui-icon aui-icon-small aui-iconfont-remove'></span></a>"
				+ "<div class='dropdown dropdown-text'><div class='text-area'><select class='js-text-expression'>"
				+ "<option value='CT'>包含</option><option value='EQ'>等于</option><option value='BT'>介于</option></select>"
				+ " <input type='text' class='textInput'  value='' /> <input hidden type='text' class='textInput'  value='' /></div></div></li>");
			} else if (type == "NUMBER" || type == "LONG") {
				$('.search-criteria-extended>ul').append("<li class='condition queryCondition' field='"
				+ field
				+ "' businessField='"
				+ businessField
				+ "' text="
				+ text
				+ " type="
				+ type
				+ "><a href='#' class='drop'>"
				+ text
				+ "：<span class='drop-text'>所有</span></a> "
				+ "<a href='#' class='remove-filter' title='删除条件' style='display: inline;'><span class='condition-remove aui-icon aui-icon-small aui-iconfont-remove'></span></a>"
				+ "<div class='dropdown dropdown-number'><div class='number-area'><select class='js-number-expression'>"
				+ "<option value='EQ'>等于</option><option value='BT'>介于</option></select>"
				+ "<input type='text' maxlength='8' class='textInput' data-type='number' value=''/>"
				+ "<input hidden type='text' class='textInput' maxlength='8' data-type='number' value='' /></div></div></li>");
			} else if (type == "STATICOPTION") {
				DWZ.ajax({
					type: 'POST',
					url: 'customQuery/getEnumList',
					data: {
						"businessType": $('#businessType').val(),
						"businessField": businessField
					},
					dataType: "json",
					cache: false,
					success: function(data) {
						var ops = "";
						if (data != null) {
							$.each(data, function(n, value) {
								ops += "<option value='" + value.value + "'>" + value.valueText + "</option>";
							});
						}
						$('.search-criteria-extended>ul').append("<li class='condition queryCondition' field='"
						+ field
						+ "' businessField='"
						+ businessField
						+ "' text="
						+ text
						+ " type="
						+ type
						+ "><a href='#' class='drop'>"
						+ text
						+ "：<span class='drop-text'>所有</span></a>"
						+ " <a href='#' class='remove-filter' title='删除条件'style='display: inline;'><span class='condition-remove aui-icon aui-icon-small aui-iconfont-remove'></span></a>"
						+ "<div class='dropdown'><div class='enum-area'><select><option value=''></option>" + ops + "</select></div></div></li>");
						resizePageBar();
					}
				});

			} else if (type == "DYNAMICOPTION") {
				$('.search-criteria-extended>ul').append("<li class='condition queryCondition' field='"
				+ field
				+ "' businessField='"
				+ businessField
				+ "' text="
				+ text
				+ " type="
				+ type
				+ "><a href='#' class='drop'>"
				+ text
				+ "：<span class='drop-text'>所有</span></a>"
				+ " <a href='#' class='remove-filter' title='删除条件'style='display: inline;'><span class='condition-remove aui-icon aui-icon-small aui-iconfont-remove'></span></a>"
				+ "<div class='dropdown'><div class='enum-area'><select><option value=''></option>" + "</select></div></div></li>");
			} else if (type == "DATETIME" || type == "DATE") {
				$('.search-criteria-extended>ul').append("<li class='condition queryCondition' field='"
				+ field
				+ "' businessField='"
				+ businessField
				+ "' text="
				+ text
				+ " type="
				+ type
				+ "><a href='#' class='drop'>"
				+ text
				+ "：<span class='drop-text'>所有</span></a>"
				+ " <a href='#' class='remove-filter' title='删除条件'  style='display: inline;'><span class='condition-remove aui-icon aui-icon-small aui-iconfont-remove'></span></a>"
				+ "<div class='dropdown dropdown-date'><div class='js-picker-ui'><div class='field-group withinTheLast'>"
				+ "<input type='radio' name='"
				+ field
				+ "' checked class='js-dp-type-toggle' id='withinTheLastRadio'><label for='withinTheLastRadio'>在过去</label>"
				+ "<input data-type='number' class='js-val digits' type='text' maxlength='8'><label for='withinTheLastRadio'>&nbsp;</label> <select class='js-measurement'><option value='MINUTE'>分</option>"
				+ "<option value='HOUR'>小时</option><option value='DAY'>天</option><option value='w'>周</option></select><label for='withinTheLastRadio'>之内</label></div>"
				+ "<div class='field-group dateBetween'><input type='radio' name='"
				+ field
				+ "' class='js-dp-type-toggle' id='dateBetweenRadio'><label for='dateBetweenRadio'>在&nbsp;</label>"
				+ "<div><input type='text' dateGroup='"+field+"' class='date from' readonly '  /> <a class='inputDateButton' href='javascript:;'>选择</a></div><label for='dateBetweenRadio'>&nbsp;和&nbsp;</label>"
				+ "<div><input type='text' dateGroup='"+field+"' class='date to' readonly'  /> <a class='inputDateButton' href='javascript:;'>选择</a></div><label for='dateBetweenRadio'>之间</label></div></div></div></li>");
			} else if ((type == "STRING" || type == "TEXT") && (field == "CREATEUSER" || field == "MODIFYUSER")) {
				$('.search-criteria-extended>ul').append("<li class='condition queryCondition' field='"
				+ field
				+ "' businessField='"
				+ businessField
				+ "' text="
				+ text
				+ " type="
				+ type
				+ "><a href='#' class='drop'>"
				+ text
				+ "：<span class='drop-text'>所有</span></a>"
				+ " <a href='#' class='remove-filter' title='删除条件'  style='display: inline;'><span class='condition-remove aui-icon aui-icon-small aui-iconfont-remove'></span></a>"
				+ "<div class='dropdown'><div class='check-list-field-container'>"
				+ "<input data-type='user' placeholder='查找用户...' class='aui-field check-list-field' id='assignee-input'>"
				+ "<span class='icon-default aui-icon aui-icon-small  noloading aui-iconfont-search'></span>"
				+ "<h5>已选中用户</h5><ul class='aui-list-section checked-list-section'></ul>"
				+ "<ul class='aui-list-section'><li class='check-list-item'><label class='item-label' title='当前用户' data-descriptor-title='当前用户'>"
				+ "<input type='checkbox' class='user-check' value='issue_current_user'>当前用户</label></li></ul>"
				+ "<ul class='aui-list-section suggest-list-section'></ul></div></div></li>");
			}
			$('.search-criteria-extended ul').initUI();
			$(this).parent().parent().remove();
			resizePageBar();
		});
		
		//移除查询条件
		page.on('click', 'span.condition-remove', function() {
			var $li = $(this).parent().parent();
			var field = $li.attr('field');
			var text = $li.attr('text');
			var type = $li.attr('type');
			var businessField = $li.attr('businessField');
			$li.remove();
			var $newLi = $("<li class='check-list-item'><label class='item-label' title='" + text + "' data-descriptor-title='" + text + "'>"
			+ "<input type='checkbox' control-type='" + type + "' value='" + field + "' businessField='" + businessField + "'>" + text
			+ "</label></li>");
			$('#all-condition').append($newLi);
			$newLi.click();
			var barHeight = $('div.search-criteria-container', page).height();
			resizePageBar();
		});
		
		//获得基本查询条件
		function getQueryCondition(li) {
			$li = $(li);
			var queryCondition = {};
			queryCondition.fieldName = $li.attr('field');
			queryCondition.businessField = $li.attr('businessField');
			queryCondition.fieldLable = $li.attr('text');
			queryCondition.dataType = $li.attr('type');
			queryCondition.operator = $li.attr('operator');
			queryCondition.fieldValue = $li.attr('fieldValue');
			queryCondition.fieldValuesStr = $li.attr('fieldValues');
			queryCondition.endValue = $li.attr('endValue');
			queryCondition.startValue = $li.attr('startValue');
			queryCondition.timeUnit = $li.attr('timeUnit');
			return queryCondition;
		}

		//查询按钮点击事件
		page.on('click', '#queryBtn', function() {
			query();
		});
		
		//保存按钮事件
		page.on('click', '#saveQuery', function() {
			submitQuery();
			var queryConditions = [];
			$('.search-criteria li.queryCondition').each(function(i, value) {
				var queryCondition = getQueryCondition(value);
				queryConditions.push(queryCondition)
			});
			var moreQueryConditions = [];
			$('.search-criteria-extended li.queryCondition').each(function(i, value) {
				$li = $(value);
				var queryCondition = getQueryCondition(value);
				moreQueryConditions.push(queryCondition)
			});
			var selectedFields = [];
			var cols = $("#head th", page);
			$.each(cols, function(n, col) {
				if (!$(col).hasClass('hidden')) {
					selectedFields.push($(col).attr('field'));
				}
			});

			DWZ.ajax({
				type: 'POST',
				url: 'customQuery/saveQuery',
				data: {
					"businessType": $('#businessType', page).val(),
					"queryConditions": JSON.stringify(queryConditions),
					"moreQueryConditions": JSON.stringify(moreQueryConditions),
					"selectedFields": JSON.stringify(selectedFields),
					"shareFlag": $('#shareFlag', page)[0].checked ? 1 : 0,
					"navTabId": $('#navTabId', page).val(),
					"screenName": $('#screenName', page).val()
				},
				dataType: "json",
				cache: false,
				success: function(data) {
					DWZ.ajaxDone(data);
				}
			});
		});
		
		//另存为
		page.on('click', '#otherSave', function() {
			var $dialogClone = $("#openWindows", page).clone(true);
			$.pdialog.open('', "editName", "保存", {
				mask: true,
				width: 320,
				height: 130,
				maxable: false,
				minable: false,
				callback: function(dialogContent) {
					dialogContent.append($dialogClone);
					$('#dialogClose', $dialogClone).click(function() {
						$.pdialog.close("editName");
					});
					$('#dialogOk', $dialogClone).click(function() {
						submitQuery();
						var queryConditions = [];
						$('.search-criteria li.queryCondition').each(function(i, value) {
							var queryCondition = getQueryCondition(value);
							queryConditions.push(queryCondition)
						});
						var moreQueryConditions = [];
						$('.search-criteria-extended li.queryCondition').each(function(i, value) {
							$li = $(value);
							var queryCondition = getQueryCondition(value);
							moreQueryConditions.push(queryCondition)
						});
						var selectedFields = [];
						var cols = $("#head th", page);
						$.each(cols, function(n, col) {
							if (!$(col).hasClass('hidden')) {
								selectedFields.push($(col).attr('field'));
							}
						});

						DWZ.ajax({
							type: 'POST',
							url: 'customQuery/addQuery',
							data: {
								"businessType": $('#businessType', page).val(),
								"queryConditions": JSON.stringify(queryConditions),
								"moreQueryConditions": JSON.stringify(moreQueryConditions),
								"selectedFields": JSON.stringify(selectedFields),
								"screenName": $('#newName', $dialogClone).val(),
								"shareFlag": $('#shareFlag', page)[0].checked ? 1 : 0,
								"navTabId": $('#navTabId', page).val()
							},
							dataType: "json",
							cache: false,
							success: function(data) {
								$.pdialog.close("editName");
								dialogAjaxDone(data);
							}
						});
					});
				}
			});
		});

		//查询
		function query(selectPage) {
			submitQuery();
			var currentPage = selectPage;
			if ($('li.selected.j-num a', page).length > 0) {
				currentPage = parseInt($('li.selected.j-num a', page).text());
			}
			if (!currentPage) {
				currentPage = 1;
			}
			var pageSize = parseInt($('a[name=numPerPage]', page).text());
			var startRow = pageSize * (currentPage - 1) + 1;
			var queryConditions = [];
			$('.search-criteria li.queryCondition').each(function(i, value) {
				var queryCondition = getQueryCondition(value);
				queryConditions.push(queryCondition)
			});
			var moreQueryConditions = [];
			$('.search-criteria-extended li.queryCondition').each(function(i, value) {
				$li = $(value);
				var queryCondition = getQueryCondition(value);
				moreQueryConditions.push(queryCondition)
			});
			DWZ.ajax({
				type: 'POST',
				url: 'customQuery/queryData',
				data: {
					"businessType": $('#businessType').val(),
					"queryConditions": JSON.stringify(queryConditions),
					"moreQueryConditions": JSON.stringify(moreQueryConditions),
					"startRow": startRow,
					"pageSize": pageSize
				},
				dataType: "json",
				cache: false,
				success: function(result) {
					$("#tbody tr", page).remove();
					$tbody = $("#tbody", page);
					var data = result.data;
					var count = result.count;
					if (data != null && data.length > 0) {
						var cols = $("#head th", page);
						$.each(data, function(n, value) {
							var tr = $("<tr/>");
							$.each(cols, function(n, col) {
								var feild = $(col).attr('field');
								feild
								var dataType = $(col).attr('dataType');
								var hidden = "";
								if ($(col).hasClass('hidden')) {
									hidden = "class='hidden'";
								}
								if (dataType == "DATE") {
									if (value[feild]) {
										tr.append("<td " + hidden + " field='" + feild + "'><div>" + new Date(value[feild]).formatDate('yyyy-MM-dd')
										+ "</div></td>");
									} else {
										tr.append("<td " + hidden + " field='" + feild + "'><div></div></td>");
									}

								} else if (dataType == "DATETIME") {
									if (value[feild]) {
										tr.append("<td " + hidden + " field='" + feild + "'><div>"
										+ new Date(value[feild]).formatDate('yyyy-MM-dd HH:mm:ss') + "</div></td>");
									} else {
										tr.append("<td " + hidden + " field='" + feild + "'><div></div></td>");
									}
								} else {
									tr.append("<td " + hidden + " field='" + feild + "'><div>" + (value[feild]||'') + "</div></td>");
								}
							});
							$tbody.append(tr);
						});
					} else {
						$tbody.append("<tr><td colspan='20' class='noRowData'>======列表无数据=====</font></td></tr>");
					}
					$.jTableTool.initGridColumnWidth($tbody.parents('.grid:first'));
					// 分页
					$('div.pages span:last', page).text(count + "条");
					var $pagination = $("div.pagination", page);
					$pagination.attr("totalCount", count);
					$pagination.attr("numPerPage", pageSize);
					$pagination.attr("currentPage", currentPage);
					var $this = $pagination;
					$this.pagination({
						targetType: $this.attr("targetType"),
						rel: $this.attr("rel"),
						totalCount: $this.attr("totalCount"),
						numPerPage: $this.attr("numPerPage"),
						pageNumShown: $this.attr("pageNumShown"),
						currentPage: $this.attr("currentPage")
					});

				}
			});
		}

		// 页码选择
		page.on('click', 'li.j-num', function() {
			var $currentSelect = $('li.selected.j-num a', page);
			var currentPage = parseInt($currentSelect.text());
			var selectPage = $(this).find('a').text();
			if (currentPage != selectPage) {
				$currentSelect.parent().removeClass('selected');
				$(this).addClass('selected');
				query();
			}

		});
		// 下一页
		page.on('click', 'li.j-next', function() {
			if (!$(this).hasClass('disabled')) {
				var $currentSelect = $('li.selected.j-num a', page);
				var currentPage = parseInt($currentSelect.text());
				var nextPage = currentPage + 1;
				$('li.j-num a:contains(' + nextPage + ')', page).parent().addClass('selected');
				$currentSelect.parent().removeClass('selected');
				query();
			}
		});
		// 上一页
		page.on('click', 'li.j-prev', function() {
			if (!$(this).hasClass('disabled')) {
				var $currentSelect = $('li.selected.j-num a', page);
				var currentPage = parseInt($currentSelect.text());
				var nextPage = currentPage - 1;
				$('li.j-num a:contains(' + nextPage + ')', page).parent().addClass('selected');
				$currentSelect.parent().removeClass('selected');
				query();
			}
		});
		// 末页
		page.on('click', 'li.j-last', function() {
			if (!$(this).hasClass('disabled')) {
				$('li.selected.j-num', page).removeClass('selected');
				var $pagination = $("div.pagination", page);
				var totalCount = parseInt($pagination.attr("totalCount"));
				var pageSize = parseInt($pagination.attr("numPerPage"));
				var maxPage = Math.ceil(totalCount / pageSize);
				query(maxPage);
			}
		});
		// 首页
		page.on('click', 'li.j-first', function() {
			if (!$(this).hasClass('disabled')) {
				$('li.selected.j-num', page).removeClass('selected');
				query(1);
			}
		});
		// 更改分页大小
		page.on('change', 'select[name=numPerPage]', function() {
			$('li.selected.j-num', page).removeClass('selected');
			query(1);
		});
		// 页码跳转
		page.on('click', 'input.goto', function() {
			var toPageText = $(this).parent().find('input.textInput').val();
			var toPage;
			if (toPageText) {
				toPage = parseInt(toPageText);
			}
			var $pagination = $("div.pagination", page);
			var totalCount = parseInt($pagination.attr("totalCount"));
			var pageSize = parseInt($pagination.attr("numPerPage"));
			var maxPage = Math.ceil(totalCount / pageSize);
			if (toPage <= maxPage) {
				$('li.selected.j-num', page).removeClass('selected');
				query(toPage);
			}
		});

		//页码跳转文本框回车事件
		page.on('keyup', 'li.jumpto input.textInput', function() {
			if (event.keyCode == DWZ.keyCode.ENTER) {
				$('input.goto', page).click();
			}
		});

	});

})(jQuery);